/*
 * JFrmPrincipal.java
 *
 * Created on 8 de Agosto de 2008, 09:47
 */

package view;

import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import utils.Conexao;
import utils.PanelFactory;



/**
 *
 * @author  Administrador
 */
public class JFrmPrincipal extends javax.swing.JFrame {


    /** Creates new form JFrmPrincipal */
    public JFrmPrincipal() {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);
        try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane = new javax.swing.JTabbedPane();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuCadastro = new javax.swing.JMenu();
        jMenuItemProduto = new javax.swing.JMenuItem();
        jMenuItemFuncionario = new javax.swing.JMenuItem();
        jMenuItemFornecedor = new javax.swing.JMenuItem();
        jMenuRotina = new javax.swing.JMenu();
        jMenuItemVenda = new javax.swing.JMenuItem();
        jMenuSair = new javax.swing.JMenu();
        jMenuItemFinalizar = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SCEV");

        jTabbedPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPaneMouseClicked(evt);
            }
        });
        jTabbedPane.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTabbedPaneKeyPressed(evt);
            }
        });

        jMenuCadastro.setMnemonic('C');
        jMenuCadastro.setText("Cadastro");
        jMenuCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuCadastroActionPerformed(evt);
            }
        });

        jMenuItemProduto.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemProduto.setText("Produto");
        jMenuItemProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemProdutoActionPerformed(evt);
            }
        });
        jMenuCadastro.add(jMenuItemProduto);

        jMenuItemFuncionario.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemFuncionario.setText("Funcionário");
        jMenuItemFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemFuncionarioActionPerformed(evt);
            }
        });
        jMenuCadastro.add(jMenuItemFuncionario);

        jMenuItemFornecedor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.SHIFT_MASK));
        jMenuItemFornecedor.setText("Fornecedor");
        jMenuItemFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemFornecedorActionPerformed(evt);
            }
        });
        jMenuCadastro.add(jMenuItemFornecedor);

        jMenuBar.add(jMenuCadastro);

        jMenuRotina.setMnemonic('C');
        jMenuRotina.setText("Rotinas");
        jMenuRotina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuRotinaActionPerformed(evt);
            }
        });

        jMenuItemVenda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemVenda.setText("Realizar vendas");
        jMenuItemVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemVendaActionPerformed(evt);
            }
        });
        jMenuRotina.add(jMenuItemVenda);

        jMenuBar.add(jMenuRotina);

        jMenuSair.setMnemonic('S');
        jMenuSair.setText("Sair");
        jMenuSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSairActionPerformed(evt);
            }
        });

        jMenuItemFinalizar.setText("Finalizar Aplicação");
        jMenuItemFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemFinalizarActionPerformed(evt);
            }
        });
        jMenuSair.add(jMenuItemFinalizar);

        jMenuBar.add(jMenuSair);

        setJMenuBar(jMenuBar);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuItemFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemFinalizarActionPerformed
    if(JOptionPane.showConfirmDialog(this,"Deseja Finalizar Aplicação?","ATENÇÂO ",JOptionPane.YES_NO_OPTION )==0){
           System.exit(0);
        }
}//GEN-LAST:event_jMenuItemFinalizarActionPerformed

private void jMenuItemFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemFuncionarioActionPerformed
        int j;
        boolean ok;
        for (ok=false,j=0; !ok && j < jTabbedPane.getTabCount(); j++ )
        {
            if (jTabbedPane.getTitleAt(j).contentEquals("Funcionários"))
            {
                jTabbedPane.setSelectedIndex(j);
                ok = true;
            }
        }
        if (!ok)
        {
            jTabbedPane.add("Funcionários", PanelFactory.getPanel("Funcionários",this) );
            jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount()-1);
            jTabbedPane.getSelectedComponent().requestFocus();
        }

}//GEN-LAST:event_jMenuItemFuncionarioActionPerformed

private void jTabbedPaneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTabbedPaneKeyPressed
          if (evt.getKeyCode()== KeyEvent.VK_ESCAPE )
            if (jTabbedPane.getSelectedIndex() > -1 )
               jTabbedPane.remove(jTabbedPane.getSelectedIndex());
}//GEN-LAST:event_jTabbedPaneKeyPressed

private void jMenuItemFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemFornecedorActionPerformed
        int j;
        boolean ok;
        for (ok=false,j=0; !ok && j < jTabbedPane.getTabCount(); j++ )
        {
            if (jTabbedPane.getTitleAt(j).contentEquals("Fornecedores"))
            {
                jTabbedPane.setSelectedIndex(j);
                ok =true;
            }
        }
        if (!ok)
        {
            jTabbedPane.add("Fornecedores", PanelFactory.getPanel("Fornecedores",this) );
            jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount()-1);
            jTabbedPane.getSelectedComponent().requestFocus();
        }
        
}//GEN-LAST:event_jMenuItemFornecedorActionPerformed

private void jTabbedPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneMouseClicked
    jTabbedPane.getSelectedComponent().requestFocus();
}//GEN-LAST:event_jTabbedPaneMouseClicked

private void jMenuItemProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemProdutoActionPerformed
        int j;
        boolean ok;
        for (ok=false,j=0; !ok && j < jTabbedPane.getTabCount(); j++ )
        {
            if (jTabbedPane.getTitleAt(j).contentEquals("Produtos"))
            {
                jTabbedPane.setSelectedIndex(j);
                ok = true;
            }
        }
        if (!ok)
        {
            jTabbedPane.add("Produtos", PanelFactory.getPanel("Produtos",this) );
            jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount()-1);
            jTabbedPane.getSelectedComponent().requestFocus();
        }
}//GEN-LAST:event_jMenuItemProdutoActionPerformed

private void jMenuCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuCadastroActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_jMenuCadastroActionPerformed

private void jMenuSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSairActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenuSairActionPerformed

private void jMenuItemVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemVendaActionPerformed
  int j;
        boolean ok;
        for (ok=false,j=0; !ok && j < jTabbedPane.getTabCount(); j++ )
        {
            if (jTabbedPane.getTitleAt(j).contentEquals("Vendas"))
            {
                jTabbedPane.setSelectedIndex(j);
                ok = true;
            }
        }
        if (!ok)
        {
            jTabbedPane.add("Vendas", PanelFactory.getPanel("Vendas",this) );
            jTabbedPane.setSelectedIndex(jTabbedPane.getTabCount()-1);
            jTabbedPane.getSelectedComponent().requestFocus();
        }
    
}//GEN-LAST:event_jMenuItemVendaActionPerformed

private void jMenuRotinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuRotinaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_jMenuRotinaActionPerformed

//    /**
//    * @param args the command line arguments
//    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrmPrincipal().setVisible(true);
            }
        });
    }
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenu jMenuCadastro;
    private javax.swing.JMenuItem jMenuItemFinalizar;
    private javax.swing.JMenuItem jMenuItemFornecedor;
    private javax.swing.JMenuItem jMenuItemFuncionario;
    private javax.swing.JMenuItem jMenuItemProduto;
    private javax.swing.JMenuItem jMenuItemVenda;
    private javax.swing.JMenu jMenuRotina;
    private javax.swing.JMenu jMenuSair;
    private javax.swing.JTabbedPane jTabbedPane;
    // End of variables declaration//GEN-END:variables
 
}
